#include <stdio.h>
int main()
{
	long long a = 0, b = 0, p = 0;
	scanf("%lld %lld %lld", &a, &b, &p);
	
	long long ans = 0;
	while ( b ) {
		if ( b & 0x01 ) {
			ans = (ans + a) % p;
		}
		a = (a * 2) % p;
		b = b >> 1;
	}
	printf("%lld", ans%p);
    return 0;
}
